import { registerClass } from "../../../cfw/tools/class_decorator";
import BaseAd from "../../core/base/BaseAd";
import { SDKState } from "../../SDKDefine";

/**
 * https://minigame.vivo.com.cn/documents/#/api/ad/box-ad?id=boxbannerad-qgcreateboxbanneradobject
 */
@registerClass('VivoBoxBannerAd')
export default class VivoBoxBannerAd extends BaseAd {
    protected name: string = "VivoBoxBannerAd"


    open() {
        this.create();
        this.show();
    }

    create() {
        this.destroy();
        if (this.sdk.createBoxBannerAd) {
            this.ad = this.sdk.createBoxBannerAd({
                posId: this.adUnitID,
                marginBottom: 100
            })
            this.ad.onError(this.getFunc(this.onError))
            this.ad.onClose(this.getFunc(this.onClose))
            // 广告数据加载成功后展示
            // this.boxBannerAd.show().then(function () { console.log('show success') })
        } else {
            console.log('暂不支持互推盒子相关 API')
        }
    }

    onClose() {
    }

    show() {
        if (this.ad) {
            this.ad.show().then(() => {
                console.log('show success')
            });
        }
    }


    close() {
        this.destroy();
    }

    destroy() {
        if (this.ad != null) {
            this.ad.offError(this.getFunc(this.onError))
            this.ad.offClose(this.getFunc(this.onClose))
            this.ad.destroy()
            this.ad = null;
        }
    }
}